local GeneratedMap = GS:addState('GeneratedMap')

function GeneratedMap:enterState()
	print("entering generated map state")
	clearLoveCallbacks()
	local lm

	if lm == nil or lm.visited == false then
		local gmap = MapGen:new(NG:get_place_name(), "G", "MedBay" )
		gmap:gen()
		gmap:gen_features()
		lm = gmap:get_map();

		draw_map(lm.layout)

		con_count = 0
		light_count = 0
		m_count = player.fire_rate*60

		local mtpts = m_get_exits(lm)

		for i = 1, #mtpts do

			Elevator:new(mtpts[i].x, mtpts[i].y, mtpts[i].dest)

		end

		lm.visited = true
		player.x = lm.features.start.x*tile_size
		player.y = lm.features.start.y*tile_size
	else

	end

	function love.update(dt)

		arc.check_keys(dt)


		global_updates(dt)

		p_update(dt)
		update_animations(dt, anims)


		light_features()

		Event:update(dt)
		Enemy:update(dt)
		Item:update(dt)
		FX:update_all(dt)

		update_proj(dt, projectiles, lm.layout)
		mouse_update(dt)

		con_count = update_con(con_count)
		light_count = p_light_energy(light_count)



	end

	function love.draw()

		love.graphics.setColor(66,66,66)
		love.graphics.draw(tileset_batch)
		Event:draw_all()
		love.graphics.setColor(255,255,255)

		--light_tiles(lm.layout)


		draw_group(features)

		draw_proj(projectiles)
		draw_animations(anims)

		Item:draw_all()

		draw_player(player)

		Enemy:draw_all()

		Fog:draw()

		FX:draw_all()

		draw_hud()

		msg_queue_draw() -- must be before arc.clear_key()

		arc.clear_key()



		draw_mouse()

	end



	function love.keypressed(key, unicode)

		arc.set_key(key)

		p_control(key,unicode, lm)

	end

	function love.mousepressed(x, y, button)

		mouse_click(x, y, button)

	end


end

function GeneratedMap:exitState()
	print("exiting generated map state")

end